package com.yang.refactor.unit_testing;

/**
 * @Description: 业务的单元测绘类
 * @Author: 杨 强
 * @CreateTime: 2022-10-14 11:25
 */
public class TextTest {

    /**
     * 测试存纯数字
     */
    public void testToNumber() {
        Text text = new Text("123");
        Assert.assertEquals(123, text.toNumber());
    }

    /**
     * 测试null值和空值
     */
    public void testToNumber_nullorEmpty() {
        Text text1 = new Text(null);
        Assert.assertNull(text1.toNumber());
        Text text2 = new Text("");
        Assert.assertNull(text2.toNumber());
    }

    /**
     * 测试数字前后左右带空格情况
     */
    public void testToNumber_containsLeadingAndTrailingSpaces() {
        Text text1 = new Text(" 123");
        Assert.assertEquals(123, text1.toNumber());
        Text text2 = new Text("123 ");
        Assert.assertEquals(123, text2.toNumber());
        Text text3 = new Text(" 123 ");
        Assert.assertEquals(123, text3.toNumber());
    }

    /**
     * 测试数字前后带多个空格的情况
     */
    public void testToNumber_containsMultiLeadingAndTrailingSpaces() {
        Text text1 = new Text("  123");
        Assert.assertEquals(123, text1.toNumber());
        Text text2 = new Text("123  ");
        Assert.assertEquals(123, text2.toNumber());
        Text text3 = new Text("  123  ");
        Assert.assertEquals(123, text3.toNumber());
    }

    /**
     * 测试数字中带字母的
     */
    public void testToNumber_containsInvalidCharaters() {
        Text text1 = new Text("123a4");
        Assert.assertNull(text1.toNumber());
        Text text2 = new Text("123 4");
        Assert.assertNull(text2.toNumber());
    }
}
